package com.diy.yuhaofilm.ui.fragment

import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.diy.yuhaofilm.R
import com.diy.yuhaofilm.adapter.HomeAdapter
import com.diy.yuhaofilm.base.BaseFragment
import com.diy.yuhaofilm.util.URLProviderUtils
import okhttp3.*
import java.io.IOException


/**
 * A simple [Fragment] subclass.
 * Use the [HomeFragment.newInstance] factory method to
 * create an instance of this fragment.
 */
class HomeFragment : BaseFragment() {

    var recycleview :RecyclerView? =null




    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        recycleview=activity?.findViewById<RecyclerView>(R.id.recycleView)
    }

    override fun initView(): View? {
       return View.inflate(context,R.layout.fragment_home,null)
    }

    override fun onResume() {
        super.onResume()
        var layoutManager=LinearLayoutManager(context)
        layoutManager.orientation=LinearLayoutManager.VERTICAL
        recycleview?.layoutManager =layoutManager
        recycleview?.adapter=HomeAdapter()

    }

    override fun initData() {
        super.initData()
        //初始化数据
        loadDatas()
    }

    private fun loadDatas() {
        val path=URLProviderUtils.getHomeUrl(0,20)
        val client=OkHttpClient()
        val request= Request.Builder().url(path).get().build()
        client.newCall(request).enqueue(object : Callback {
            /**
             * 子线程调用
             */
            override fun onFailure(call: Call, e: IOException) {

            }

            override fun onResponse(call: Call, response: Response) {

            }

        })

    }


}